{{ if .Values.controlPlane.service.enabled }}
apiVersion: v1
kind: Service
metadata:
  name: {{ include "kuma.controlPlane.serviceName" . }}
  namespace: {{ .Release.Namespace }}
  labels: {{ include "kuma.cpLabels" . | nindent 4 }}
  annotations:
    {{- range $key, $value := .Values.controlPlane.service.annotations }}
    {{- if $value }}
    {{ $key }}: {{ $value | quote }}
    {{- end }}
    {{- end }}
spec:
  type: {{ .Values.controlPlane.service.type }}
  ports:
    - port: 5680
      name: diagnostics
      appProtocol: http
    - port: 5681
      name: http-api-server
      appProtocol: http
      {{- if and (eq .Values.controlPlane.service.type "NodePort") .Values.controlPlane.service.apiServer.http.nodePort }}
      nodePort: {{ .Values.controlPlane.service.apiServer.http.nodePort }}
      {{- end }}
    - port: 5682
      name: https-api-server
      appProtocol: https
      {{- if and (eq .Values.controlPlane.service.type "NodePort") .Values.controlPlane.service.apiServer.https.nodePort }}
      nodePort: {{ .Values.controlPlane.service.apiServer.https.nodePort }}
      {{- end }}
    {{- if ne .Values.controlPlane.environment "universal" }}
    - port: 443
      name: https-admission-server
      targetPort: {{ .Values.controlPlane.admissionServerPort | default "5443" }}
      appProtocol: https
    {{- end }}
    {{- if ne .Values.controlPlane.mode "global" }}
    - port: 5676
      name: mads-server
      appProtocol: https
    - port: 5678
      name: dp-server
      appProtocol: https
    {{- end }}
  selector:
    app: {{ include "kuma.name" . }}-control-plane
  {{- include "kuma.selectorLabels" . | nindent 4 }}
{{ end }}
